package com.neotec.quientienemail.i3.server.recibe;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Vector;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.griaule.grfingerjava.FingerprintImage;
import com.griaule.grfingerjava.IFingerEventListener;
import com.griaule.grfingerjava.IImageEventListener;
import com.griaule.grfingerjava.IStatusEventListener;
import com.griaule.grfingerjava.GrFingerJava;
import com.griaule.grfingerjava.GrFingerJavaException;
import com.griaule.grfingerjava.MatchingContext;
import com.griaule.grfingerjava.Template;
import java.net.URL;
import java.net.URLConnection;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class RecibeHuellas extends HttpServlet {

	/**
	 * Constructor of the object.
	 */
	
	public Vector templateVector;
	
	public RecibeHuellas() {
		super();
	}
    private Vector TemplateVector = null;
    
	/**
	 * Destruction of the servlet. <br>
	 */
	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	/**
	 * The doGet method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to get.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doProcesa(request,response);
	}

	/**
	 * The doPost method of the servlet. <br>
	 *
	 * This method is called when a form has its tag value method equals to post.
	 * 
	 * @param request the request send by the client to the server
	 * @param response the response send by the server to the client
	 * @throws ServletException if an error occurred
	 * @throws IOException if an error occurred
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doProcesa(request,response);
	}

	public void doProcesa(HttpServletRequest request, HttpServletResponse response) throws IOException
	{
		
        // reference to Object class
        Object obj = null;

        // get the URLConnection to the servlet
   
        

        // get the Object input stream
        ObjectInputStream inputFromServlet = null;
        inputFromServlet = new ObjectInputStream(request.getInputStream());
        // read the serialized object from the input stream, it may be a Vector 
        // or an exception.
        try {
			obj = inputFromServlet.readObject();
			if (obj instanceof Vector)
			{
				templateVector = (Vector) obj;
				
			}
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		String a = "";
		a = templateVector.lastElement().toString();
        // close the objectInputStream 
        inputFromServlet.close();
		
		
		response.setContentType("application/octet-stream");
		
		ObjectOutputStream outputToApplet = null;
		
		outputToApplet = new ObjectOutputStream(response.getOutputStream());
		outputToApplet.writeObject(a);
        outputToApplet.flush();
        outputToApplet.close();
		
		
	}
	/**
	 * Initialization of the servlet. <br>
	 *
	 * @throws ServletException if an error occure
	 */
	public void init() throws ServletException {
		// Put your code here
	}

}
